//
//  WebViewViewController.m
//  BaseTools
//
//  Created by 李挺哲 on 15/8/20.
//  Copyright (c) 2015年 ltz. All rights reserved.
//

#import "WebViewViewController.h"
#import "MJRefresh.h"

@interface WebViewViewController ()

@end

@implementation WebViewViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self initNavigationTitle:@"网页" barTintColor:0x1E86CB titleColor:0xFFFFFF isTranslucent:NO isHidden:NO];
    [self showNavigationLeftButtonTitle:@"返回" tintColor:0xFFFFFF];

    [self.webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:_url]]];
//    __weak UIWebView *webView = self.webView;
    __weak UIScrollView *scrollView = self.webView.scrollView;
    
    // 添加下拉刷新控件
    scrollView.header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
        [_webView reload];
    }];
    
    // 如果是上拉刷新，就以此类推
    
    
}

#pragma mark - webViewDelegate
- (void)webViewDidFinishLoad:(nonnull UIWebView *)webView
{
    [self dismissIndicatorView];
    [self.webView.scrollView.header endRefreshing];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    
}

- (void)webViewDidStartLoad:(UIWebView *)webView{

    [self showIndicatorView:kNetworkConnecting];
}
- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error{
    
    
    if([error code] == NSURLErrorCancelled)
    {
        return;
    }else{
    [self dismissIndicatorView];
    NSLog(@"error %@",error);
    [self.view makeToast:kNetworkNotConnect];
    }
    


}

@end
